package com.kl.reconnect;

import com.kl.decodeandencode.MyMessage;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInboundHandlerAdapter;
import io.netty.channel.SimpleChannelInboundHandler;

public class NettyClientHandler extends ChannelInboundHandlerAdapter {

    private final NettyClient client = new NettyClient("127.0.0.1", 9000);

    /**
     * 只要有消息就会触发读取
     */
    @Override
    public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
        System.out.println(msg);
    }

    /**
     * 通道关闭时会触发
     */
    @Override
    public void channelInactive(ChannelHandlerContext ctx) throws Exception {
        System.err.println("===连接被断开===");
        client.connect();
    }
}
